// pages/signup/signup.js

var app=getApp();
var ea = require('../../utils/each.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    get_course: app.data.url +'/zhongxue/maoapi/get_course',
    xiala: app.data.url +'/uploads/zhongxue/xiala.png',
    arrayxiao: ["成都校区", "北京校区","成都校区", "北京校区"],
    arrayduan: ["小学", "初中", "高中","大学"],
    arraynian: ["一年级", "二年级", "三年级", "四年级"],
    arrayke: ["语文", "数学", "英语", "化学"],
    xiaoqus: app.data.url +"/uploads/zhongxue/xiaoqu.png",
    date: app.data.url +"/uploads/zhongxue/date.png",
    xdate: app.data.url +"/uploads/zhongxue/xdate.png",
    mains: [
      {
        jiaoshi: {
          state:'lanse',
          zhi:"开班中",
          title: "【2019暑】四年级趣味语文入门教学成才",
          kemu: "语文",
          banji: "3班",
          renshu: "30人",
          leixing: '提高',
          liulanc: "浏览25次",
          date:"06月12日-12月30日",
          xdate:"周日16：00-22：00",
          xiaoqu:"成都校区",
          money:"15000.00",
        },
        teacher: {
          src: app.data.url +"/uploads/zhongxue/laoshiimg.png",
          name: "张老师",
          mine: "剩余名额10人",
        },
      },

      {
        jiaoshi: {
          state: 'huise',
          zhi: "报名截止",
          title: "【2019暑】四年级趣味语文入门教学成才",
          kemu: "语文",
          banji: "3班",
          renshu: "30人",
          leixing: '提高',
          liulanc: "浏览25次",
          date: "06月12日-12月30日",
          xdate: "周日16：00-22：00",
          xiaoqu: "成都校区",
          money: "15000.00",
        },
        teacher: {
          src: app.data.url +"/uploads/zhongxue/laoshiimg.png",
          name: "张老师",
          mine: "剩余名额10人",
        },
      },

      {
        jiaoshi: {
          state: 'huise',
          zhi: "报名截止",
          title: "【2019暑】四年级趣味语文入门教学成才",
          kemu: "语文",
          banji: "3班",
          renshu: "30人",
          leixing: '提高',
          liulanc: "浏览25次",
          date: "06月12日-12月30日",
          xdate: "周日16：00-22：00",
          xiaoqu: "成都校区",
          money: "15000.00",
        },
        teacher: {
          src: app.data.url +"/uploads/zhongxue/laoshiimg.png",
          name: "张老师",
          mine: "剩余名额10人",
        },
      },

    ],
  tiaojian:{},
  page:1,
  shuju:[],
  fujia:{},
  xianshi:{
    campus: 0,
    section: 0,
    grades: 0,
    curriculum:0
  }
  },
  sigups: function (e) {
    var user = wx.getStorageSync('user');
    console.log(user);
    if(user.denglu!==1){
      wx.showToast({
        title: '你还没有登录！',
        icon:'none',
        duration: app.data.quanbushijian
      })
      setTimeout(function(){
        wx.navigateTo({
          url: '/pages/login/login',
        })
      },1300)
      return;
    }
    var id = e.currentTarget.dataset.id;
    var go = e.currentTarget.dataset.go;
    var phone = e.currentTarget.dataset.phone;
    if(go==0){
     wx.showModal({
       title: ' 提示',
       content: '本班报名已截止,请联系班主任',
       confirmText:'打电话',
       success:function(e){
         if (e.confirm){
           wx.makePhoneCall({
             phoneNumber: phone,
           })
         }
       }
     })
      return
    }
    if (user.denglu == 1) {
      wx.navigateTo({
        url: '/pages/lgsigup/lgsigup?id='+id,
      })
    } else {
      wx.navigateTo({
        url: '/pages/login/login',
      })
    }
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },
  getData:function(){
    var page = this.data.page;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none',
        duration: app.data.quanbushijian
      })
      return
    }
    var tiaojian = this.data.tiaojian;
    var user = wx.getStorageSync('user');
    tiaojian.token = user.token;
    tiaojian.page = page;
    var that = this;
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: that.data.get_course,
      data: tiaojian,
      method:'post',
      success:function(res){
        var data = res.data;
        if(data.code==200){
          // console.log(data.data);
          var newshuju = data.data.data;
          var fujia = data.data.fujia;
          var shuju = that.data.shuju;
          if(newshuju.length<10){
            that.setData({page:0});
          }else{
            that.setData({page:page+1})
          }
          ea.each(newshuju,function(i,v){
            shuju.push(v)
          })
          // console.log(shuju);
          // console.log(fujia);
          that.setData({shuju:shuju,fujia:fujia});
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none',
            duration: app.data.quanbushijian
          })
        }
        wx.hideLoading();
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  bindPickerChange:function(e){
    var key = e.currentTarget.dataset.key;
    var value = e.detail.value;
    var fujia = this.data.fujia;
    var tiaojian = this.data.tiaojian;
    console.log(key);
    // return
    if(fujia[key][value].id){
      tiaojian[key] = fujia[key][value].id;
    }else{
      tiaojian[key] = '';
    }
    var xianshi = this.data.xianshi;
    if (key =="section"){
      xianshi.grades = 0;
      tiaojian.grades = '';
    }
    xianshi[key] =value;
    console.log(tiaojian);
    this.setData({ fujia: fujia, page: 1, shuju: [], xianshi: xianshi, tiaojian: tiaojian});
    var that = this;
    this.getData();

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({shuju:[],tiaojian:{},page:1,xianshi:{
      campus: 0,
      section: 0,
      grades: 0,
      curriculum: 0
    }});
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getData();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      path: '/pages/indexfirst/indexfirst',
    }
  }
})